import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from "vue-router";
const routes: Array<RouteRecordRaw> = [
  // 项目打开后进入的默认地址
  {
    path: "/",
    name: "index",
    component: () => import("@/views/index.vue")
  },
  {
    path: "/user",
    name: "user",
    component: () => import("@/views/user.vue")
  },
  {
    path: "/viewFile",
    name: "viewFile",
    component: () => import("@/views/viewFile.vue"),
  },
  {
    path: "/viewFile/:id",
    name: "viewFileById",
    component: () => import("@/views/viewFile.vue"),
  },
  {
    path: "/viewFile/:officeType/:id",
    name: "viewFileByIdAndOfficeType",
    component: () => import("@/views/viewFile.vue"),
  }
];
const router = createRouter({
  history: createWebHistory("/html/document/"), // 本项目采用了哈希模式 createWebHashHistory
  routes,
});

// 通过路由修改title
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  // console.log(to);
  let title = '钱大妈-文件查看'
  if(to.params && to.params.id){
    title = '钱大妈-' + to?.params?.id
  }
  document.title = title;
  next();
});
export default router;
